<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料号" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标签编号" prop="lableCode">
        <el-input
          v-model="queryParams.lableCode"
          placeholder="请输入标签编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="器具位置号" prop="applianceyCode">
        <el-input
          v-model="queryParams.applianceyCode"
          placeholder="请输入器具位置号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="器具名称" prop="applianceyName">
        <el-input
          v-model="queryParams.applianceyName"
          placeholder="请输入器具名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商编号" prop="suppCode">
        <el-input
          v-model="queryParams.suppCode"
          placeholder="请输入供应商编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商名称" prop="suppName">
        <el-input
          v-model="queryParams.suppName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="sps区" prop="spsArea">
        <el-input
          v-model="queryParams.spsArea"
          placeholder="请输入sps区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线体编号" prop="lineCode">
        <el-input
          v-model="queryParams.lineCode"
          placeholder="请输入线体编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线体名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入线体名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排产日期" prop="pcDate">
        <el-date-picker clearable
          v-model="queryParams.pcDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择排产日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:ccorderinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:ccorderinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:ccorderinfo:remove']"
        >删除</el-button>
      </el-col>-->

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入订单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:ccorderinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ccorderinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="分拣状态" align="center" prop="res5" />
      <el-table-column label="订单编号" align="center" prop="orderCode" width="150px"/>
      <el-table-column label="物料号" align="center" prop="itemCode" width="150"/>
      <el-table-column label="物料名称" align="center" prop="itemName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="标签编号" align="center" prop="lableCode" />
      <el-table-column label="器具位置编号" align="center" prop="applianceyCode" width="150"/>
      <el-table-column label="器具编号" align="center" prop="res3"/>
      <el-table-column label="器具名称" align="center" prop="applianceyName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="供应商编号" align="center" prop="suppCode" width="150"/>
      <el-table-column label="供应商名称" align="center" prop="suppName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="单车数量" align="center" prop="dcNum" />
      <el-table-column label="分拣数量" align="center" prop="fjNum" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="sps区" align="center" prop="spsArea" />
      <el-table-column label="段位" align="center" prop="res4"/>
      <el-table-column label="线体编号" align="center" prop="lineCode" />
      <el-table-column label="线体名称" align="center" prop="lineName" />
      <el-table-column label="排产日期" align="center" prop="pcDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pcDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="bz" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createUser" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:ccorderinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:ccorderinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="分拣状态" prop="res5">
          <el-input v-model="form.res5" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="物料号" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入物料号" />
        </el-form-item>
        <el-form-item label="物料名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="标签编号" prop="lableCode">
          <el-input v-model="form.lableCode" placeholder="请输入标签编号" />
        </el-form-item>
        <el-form-item label="器具位置编号" prop="applianceyCode">
          <el-input v-model="form.applianceyCode" placeholder="请输入器具位置编号" />
        </el-form-item>
        <el-form-item label="器具编号" prop="res3">
          <el-input v-model="form.res3" placeholder="请输入器具编号" />
        </el-form-item>
        <el-form-item label="器具名称" prop="applianceyName">
          <el-input v-model="form.applianceyName" placeholder="请输入器具名称" />
        </el-form-item>
        <el-form-item label="供应商编号" prop="suppCode">
          <el-input v-model="form.suppCode" placeholder="请输入供应商编号" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="suppName">
          <el-input v-model="form.suppName" placeholder="请输入供应商名称" />
        </el-form-item>
        <el-form-item label="分拣数量" prop="fjNum">
          <el-input v-model="form.fjNum" placeholder="请输入分拣数量" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="sps区" prop="spsArea">
          <el-input v-model="form.spsArea" placeholder="请输入sps区" />
        </el-form-item>
        <el-form-item label="线体编号" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入线体编号" />
        </el-form-item>
        <el-form-item label="线体名称" prop="lineName">
          <el-input v-model="form.lineName" placeholder="请输入线体名称" />
        </el-form-item>
        <el-form-item label="排产日期" prop="pcDate">
          <el-date-picker clearable
            v-model="form.pcDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择排产日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 订单导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <div style="float: left;font-size: 16px;line-height: 40px;">请选择排产日期：
        <el-date-picker clearable size="small"
                        v-model="upload.pcDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择排产日期">
        </el-date-picker>
      </div>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?pcDate=' + upload.pcDate" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <!--   <div class="el-upload__tip" slot="tip">
               <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
             </div>-->
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listCcorderinfo, getCcorderinfo, delCcorderinfo, addCcorderinfo, updateCcorderinfo } from "@/api/business/ccorderinfo";
import { getToken } from "@/utils/auth";
export default {
  name: "Ccorderinfo",
  dicts: ['order_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      ccorderinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        orderCode: null,
        itemCode: null,
        itemName: null,
        lableCode: null,
        applianceyCode: null,
        applianceyName: null,
        suppCode: null,
        suppName: null,
        dcNum: null,
        fjNum: null,
        unit: null,
        spsArea: null,
        lineCode: null,
        lineName: null,
        pcDate: null,
        bz: null,
        createUser: null,
        res1: null,
        res2: null,
        res3: null,
        res4: null,
        res5: null
      },
      // 表单参数
      form: {},

      // 物料导入参数
      upload: {
        // 是否显示弹出层（订单导入）
        open: false,
        // 弹出层标题（订单导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的物料数据
        updateSupport: 0,
        //排产日期
        pcDate:null,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/business/ccorderinfo/importData"
      },

      // 表单校验
      rules: {
      }
    };
  },
  created() {
    //this.getList();
  },
  methods: {

    getList() {
      this.loading = true;
      listCcorderinfo(this.queryParams).then(response => {
        this.ccorderinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询订单信息列表 */
    getListInfoFj(res1) {
      this.loading = true;
      this.queryParams.res1 = res1;
      listCcorderinfo(this.queryParams).then(response => {
        this.ccorderinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },



    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: null,
        orderCode: null,
        itemCode: null,
        itemName: null,
        lableCode: null,
        applianceyCode: null,
        applianceyName: null,
        suppCode: null,
        suppName: null,
        dcNum: null,
        fjNum: null,
        unit: null,
        spsArea: null,
        lineCode: null,
        lineName: null,
        pcDate: null,
        bz: null,
        createUser: null,
        res1: null,
        res2: null,
        res3: null,
        res4: null,
        res5: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCcorderinfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCcorderinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCcorderinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单信息编号为"' + ids + '"的数据项？').then(function() {
        return delCcorderinfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },


    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "物料导入";
      this.upload.open = true;
    },

    /** 下载模板操作 */
    importTemplate() {
      this.download('business/ccorderinfo/importTemplate', {
      }, `订单导入_${new Date().getTime()}.xlsx`)
    },

    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },


    /** 导出按钮操作 */
    handleExport() {
      this.download('business/ccorderinfo/export', {
        ...this.queryParams
      }, `ccorderinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
